﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JXMSTC2.Model;
using JXMSTC2.Control;

public partial class InfoManage_UserControl_cColumnManage : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitState();
            if (Request["id"] != null)
            {
                EditState();
                BindData(int.Parse(Request["id"].ToString()));
            }
            else
            {
                AddState();
            }
        }
    }



    #region 按钮的状态选择

    /// <summary>
    /// 初始按钮状态
    /// </summary>
    protected void InitState()
    {
        btnAdd.Visible = false;
        BtnCancle.Visible = false;
        BtnSave.Visible = false;
    }

    /// <summary>
    /// 编辑状态
    /// </summary>
    protected void EditState()
    {
        BtnCancle.Visible = true;
        BtnSave.Visible = true;
    }

    /// <summary>
    /// 新增状态
    /// </summary>
    protected void AddState()
    {
        btnAdd.Visible = true;
        BtnSave.Visible = true;
    }

    #endregion



    #region 操作控制的方法
    /// <summary>
    /// 初始化类别
    /// </summary>
    /// <param name="ID">类别的ＩＤ</param>
    protected void BindData(int ID)
    {
        InfoCategoryModelControl infocon = new InfoCategoryModelControl();
        InfoCategory info = infocon.GetModel(ID);
        this.txbTitle.Text = Server.HtmlDecode(info.Category);

    }

    /// <summary>
    /// 更新类别
    /// </summary>
    /// <param name="ID">类别的ID</param>
    protected void UpdateData(int ID)
    {
        InfoCategoryModelControl infocon = new InfoCategoryModelControl();
        InfoCategory tech = infocon.GetModel(ID);
        tech.Category = Server.HtmlEncode(this.txbTitle.Text);
        infocon.Update(tech);
        MessageBox.ShowAndRedirect(Page, "修改成功", "ColumnManageList.aspx");
    }

    /// <summary>
    /// 增加类别
    /// </summary>
    protected void AddData()
    {
        InfoCategoryModelControl infocon = new InfoCategoryModelControl();
        InfoCategory tech = new InfoCategory();
        tech.Category = Server.HtmlEncode(this.txbTitle.Text);

        infocon.Add(tech);
        MessageBox.ShowAndRedirect(Page, "提交成功", "ColumnManageList.aspx");
    }
    #endregion



    #region 按钮自动生成的方法

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        AddData();
    }

    protected void BtnSave_Click(object sender, EventArgs e)
    {
        UpdateData(int.Parse(Request["id"].ToString()));
    }

    protected void BtnCancle_Click(object sender, EventArgs e)
    {
        Response.Redirect("ColumnManageList.aspx");
    }
    #endregion
}
